/**
 * Copyright (c) 2021 Choice, Inc.
 * All Rights Reserved.
 * Choice Proprietary and Confidential.
 */
package cn.ruleengine.web.aspect;

import java.lang.reflect.Method;

import javax.annotation.Resource;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import cn.ruleengine.web.annotation.RuleSetChange;
import cn.ruleengine.web.mq.RuleSetChangeProducer;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Aspect
@Order(-20)
@Component
public class RuleSetChangeAspect {

    @Resource
    private RuleSetChangeProducer ruleSetChangeProducer;

    @AfterReturning("@annotation(ruleSetChange)")
    public void around(JoinPoint joinPoint, RuleSetChange ruleSetChange) throws Throwable {
        MethodSignature ms = (MethodSignature) joinPoint.getSignature();
        Method method = ms.getMethod();
        log.info("规则集改变刷新内存: {}", method.getName());
        ruleSetChangeProducer.broadcast(method.getName(), joinPoint.getArgs());
    }
}
